<!-- 模块管理 -->
<template>
	{{ option.pageOption }}
	<BaseTable
		:option="option"
		@searchHandler="searchBtnClick"
		:eventOption="{
			createSubmit
		}"
		searchBtn
	/>
</template>

<script setup lang="ts">
import { getMenuListApi, addMenu } from "@/api/config";
import { ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const option = ref({
	column: [
		{
			prop: "menuType",
			label: "菜单类型",
			form: true,
			type: "Select",
			dict: [
				{ value: "1", label: "顶部菜单" },
				{ value: "2", label: "功能模块" },
				{ value: "3", label: "功能页面" },
				{ value: "4", label: "按钮" }
			]
		},
		{
			prop: "parentMenuId",
			label: "上级菜单",
			form: true,
			type: "Select",
			dict: [
				{ value: "1", label: "顶部菜单" },
				{ value: "2", label: "功能模块" },
				{ value: "3", label: "功能页面" }
			]
		},
		{
			prop: "menuName",
			label: "菜单名称",
			form: true
		},
		{
			prop: "shortName",
			label: "名称简称",
			form: true,
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		},
		{
			prop: "menuUrl",
			label: "菜单地址",
			form: true,
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		},

		{
			prop: "menuOrder",
			label: "排序",
			type: "Number",
			form: true,
			search: true,
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		},
		{
			prop: "menuIcon",
			label: "菜单图标",
			search: true,
			type: "Icon",
			form: true,
			default: "#icon-a-chartanalysisstatisticsreport",
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		},
		{
			prop: "menuStatus",
			label: "菜单状态",
			type: "Select",
			form: true,
			dict: [
				{ value: "1", label: "生效" },
				{ value: "2", label: "失效" }
			],
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		},
		{
			prop: "remark",
			label: "备注",
			type: "Textarea",
			inputSpan: 24,
			form: true,
			rules: [
				{
					required: true,
					message: "Please"
				}
			]
		}
	],
	data: [],
	page: true,
	pageConfig: { pageKey: "currentPage", sizeKey: "pageSize" },
	pageOption: { currentPage: 1, pageSize: 20, total: 0 }
});
const page = ref({});

const getMenuList = async (search) => {
	try {
		let result = await getMenuListApi(search);
		option.value.data = result.data.data;
		console.log("获取菜单列表：", result);
	} catch (error) {
		console.log("获取菜单列表失败：", error);
	}
};
//搜索按钮点击
const searchBtnClick = (search) => {
	console.log(search, "search");
	getMenuList(search);
};
/**
 * 新增确定-按钮
 * @param form 表单内容
 * @param done 关闭弹出功能
 */
const createSubmit = async (form, done) => {
	try {
		await addMenu(form.value);
		searchBtnClick();
		done();
	} catch (error) {
		console.log("新增确定-报错：", error);
	}
};
</script>

<style lang="less" scoped></style>
